package greg1992.lekcja4.gui;

import greg1992.lekcja3.turniej.Druzyna;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;


public class DruzynaGUI extends JFrame {


	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField txtNazwaDruzyny;

	private Druzyna druzynaDane;
	private JButton btnZapisz;



	/**
	 * Create the frame.
	 */
	public DruzynaGUI(Druzyna druzyna) {
		this.druzynaDane = druzyna;
		
		setTitle("druzynaGUI");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 335, 171);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		FormLayout fl_contentPane = new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,});
		contentPane.setLayout(fl_contentPane);
		
		JLabel lblNazwaDruzyny = new JLabel("Nazwa druzyny");
		contentPane.add(lblNazwaDruzyny, "4, 4, right, default");
		
		txtNazwaDruzyny = new JTextField(druzynaDane.getNazwa());
		contentPane.add(txtNazwaDruzyny, "6, 4, fill, default");
		txtNazwaDruzyny.setColumns(10);
		
		
		
		btnZapisz = new JButton("Zapisz");
		contentPane.add(btnZapisz, "6, 6");
		
		btnZapisz.addActionListener( new ActionListener(){
			public void actionPerformed(ActionEvent e){
				zapiszDane();
			}
		});
	}
	
	

	
	void zapiszDane(){
		druzynaDane.setNazwa( txtNazwaDruzyny.getText() );
		druzynaDane.wypiszAtrybutyDoKonsoli();
	}
	
}
